#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define ON 1
#define OFF 0
#define LED2 0
#define LED3 1

int main(void)
{
	int fd;
	char *hello_node = "/dev/chardev0";

	if((fd = open(hello_node,O_RDWR|O_NDELAY))<0){
		printf("APP open %s failed\n",hello_node);
	}

	int loop_i = 1;
	for(loop_i; loop_i <= 20; loop_i++)
	{
		if(loop_i % 3 == 0)
		{
			//turn led on;
			printf("turn on led2\n");
			ioctl(fd, ON, LED2);
		}
		else
		{
			//turn led off
			printf("turn off led2\n");
			ioctl(fd, OFF, LED2);
		}
		sleep(1);
	}

	//led3
	loop_i = 1;
	int ret;
	for(loop_i; loop_i <= 20; loop_i++)
	{
		if(loop_i % 3 == 0)
		{
			//turn led on;
			ret = ioctl(fd, ON, LED3);
			printf("turn on ret = %d\n", ret);
		}
		else
		{
			//turn led off
			ret = ioctl(fd, OFF, LED3);
			printf("turn off ret = %d\n", ret);
		}
		sleep(1);
	}

	close(fd);
}

